import socket

# 1. 创建socket对象(买手机)
phone = socket.socket() # 可以默认不写

# 连接服务器ip地址与端口
phone.connect(('127.0.0.1', 8888))

# 发消息
while 1:
    to_server = input('>>>').strip()
    if to_server.upper() == 'Q':
        phone.send('q'.encode('utf-8'))
        break
    phone.send(to_server.encode('utf-8'))
    # 接收消息
    from_server_data = phone.recv(1024)  # 夯住,等待服务端的数据传过来
    print(f'来自服务端消息:{from_server_data.decode("utf-8")}')

# 关机
phone.close()


